package com.zsix.system.strategy.processVariables;

import com.zsix.system.mapper.SqlMapper;
import com.zsix.common.dto.controllerParams.ProceParams;
import com.zsix.common.entity.taskAssignee.GenerWork;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class SqlParams implements ProcessVariableStrategy {
    @Autowired
    private SqlMapper sqlMapper;
    /**
     * 参数赋值
     * @param generWork
     * @param proceParams
     * @return
     */
    @Override
    public HashMap<String,Object> SetParams(GenerWork generWork,
             ProceParams proceParams, HashMap<String,Object> hashMap,String processKey,String task_def_key
            ,String BusinessKey){
        List<Map<String,Object>> sqlDataList=sqlMapper.list(proceParams.getParamValue(),null);
        String sqlValue="";
        //避免查询的数据有多条，只取最后一个参数传入
        for(Map<String,Object> map:sqlDataList){
            sqlValue=map.get(proceParams.getParamKey()).toString();
        }
        if(proceParams.getValueType().equals("2"))//布尔型
            hashMap.put(proceParams.getParamKey(), Boolean.valueOf(sqlValue));
        else if(proceParams.getValueType().equals("1"))//数值型
            hashMap.put(proceParams.getParamKey(), Float.valueOf(sqlValue));
        else//字符型
            hashMap.put(proceParams.getParamKey(), sqlValue);
        return hashMap;
    }
    @Override
    public String getType(){
        return "2";
    }
}
